package top.zsyle.basic.dto;

import lombok.Data;
import top.zsyle.basic.util.MD5Utils;
import top.zsyle.basic.util.StrUtils;
import top.zsyle.user.domain.User;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class BinderDto {

    @NotBlank(message = "绑定电话不能为空")
    private String phone;
    @NotBlank(message = "验证码不能为空")
    private String verifyCode;
    @NotBlank(message = "accessToken不能为空")
    private String accessToken;
    @NotBlank(message = "openId不能为空")
    private String openId;

    public User getUser(){
        //获取盐值
        String salt = StrUtils.getComplexRandomString(32);
        //加密密码
        String password = MD5Utils.encrypByMd5(salt + "123456");
        return User.builder()
                .username(this.phone)
                .phone(this.phone)
                .salt(salt)
                .password(password)
                .state(1)
                .createtime(new Date())
                .build();
    }
}
